package qcmPlus.dao;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Session;

import qcmPlus.beans.Reponse;
import qcmPlus.tools.HibernateUtil;

public class ReponseDAO {

	private List<Reponse> listeReponses = new ArrayList<Reponse>();

	@SuppressWarnings("unchecked")
	public List<Reponse> liste(int idQuestion) {

		ArrayList<Reponse> temp = null;
		Session s = HibernateUtil.currentSession();

		temp = (ArrayList<Reponse>) s.createQuery(
				"from Reponse where ID_QUESTION=" + idQuestion +" order by ID_REPONSE asc" ).list();
		if (temp.size() > 0) {
			for (Reponse r : temp) {
				listeReponses.add(r);
			}
		}

		HibernateUtil.closeSession();
		return listeReponses;
	}
	
	@SuppressWarnings("unchecked")
	public List<Reponse> listeBonneReponse(int idQuestion) {

		ArrayList<Reponse> temp = null;
		Session s = HibernateUtil.currentSession();

		temp = (ArrayList<Reponse>) s.createQuery(
				"from Reponse where ID_QUESTION=" + idQuestion +" AND EST_BONNE_REPONSE = 1  order by ID_REPONSE asc" ).list();
		
		if (temp.size() > 0) 
		{
			for (Reponse r : temp) {
				listeReponses.add(r);
			}
		}

		HibernateUtil.closeSession();
		return listeReponses;
	}
	
	
	public Reponse getReponse(int id) 
	{

		Session s = HibernateUtil.currentSession();
		Reponse reponse = (Reponse) s.get(Reponse.class, id);
		HibernateUtil.closeSession();
		return reponse;

	}
	
	
		
}
